#!/bin/bash
set -e

# Set debug mode
set -x
set -v

# Add robotpkg
sudo sh -c "echo \"deb [arch=amd64] http://robotpkg.openrobots.org/packages/debian/pub $(lsb_release -cs) robotpkg\" >> /etc/apt/sources.list "
curl http://robotpkg.openrobots.org/packages/debian/robotpkg.key | sudo apt-key add -
sudo apt update

# show memory usage before install
sudo free -m -t

# Setup environment variables.
export APT_DEPENDENCIES="doxygen libboost-system-dev libboost-test-dev libboost-filesystem-dev libboost-program-options-dev libeigen3-dev liburdfdom-dev texlive-font-utils libmpfr-dev"

# Add Python dependency
echo "TRAVIS_PYTHON_VERSION=$TRAVIS_PYTHON_VERSION"
if [[ $TRAVIS_PYTHON_VERSION -gt 30 ]]; then
  export APT_DEPENDENCIES=$APT_DEPENDENCIES" libboost-python-dev robotpkg-py36-eigenpy python3.6-dev python-numpy"
else
  export APT_DEPENDENCIES=$APT_DEPENDENCIES" libboost-python-dev robotpkg-py27-eigenpy python2.7-dev python-numpy"
fi

# Add Geometry dependencies
if [[ $BUILD_WITH_COLLISION_SUPPORT -eq ON ]]; then
  export APT_DEPENDENCIES=$APT_DEPENDENCIES" robotpkg-hpp-fcl robotpkg-py${TRAVIS_PYTHON_VERSION}-hpp-fcl"
fi

# When this script is called the current directory is ./custom_travis
. ./.travis/run ../.travis/before_install

# Git fetch tags
git fetch --tags
git tag

# End debug mode
set +v
set +x
